<?php
	session_start();
    include('conn.php');
	
	$tno=$_REQUEST['tno'];	
	$pnr=$_REQUEST["pnr"];
	$pax=$_REQUEST["pax"];
	$tdt1=$_REQUEST["tdt"];
	$tdlen = strlen($tdt1);			
	$rdt1=$_REQUEST["rdt"];
	$rdlen = strlen($rdt1);	
	$bdt1=$_REQUEST["bdt"];
	$bdlen = strlen($bdt1);	
	$sec=$_REQUEST["sec"];
	$bc=$_REQUEST["bc"];
	$ac=$_REQUEST["ac"];
	$tax=$_REQUEST["tax"];
	$amt=$_REQUEST["amt"];	
	$nature=$_REQUEST["nature"];	
	$rev1=$_REQUEST['rev1'];
	$rev2=$_REQUEST['rev2'];
	$rev3=$_REQUEST['rev3'];
	$upddr=$_REQUEST['upddr'];
	$updcr=$_REQUEST['updcr'];
	$username = $_SESSION['username'];
	
	$sql2="SELECT MAX(trnid) FROM  transactionmast where enteredby = '$username'"; 	
	$res2=mysql_query($sql2);			
	while($rows = mysql_fetch_array($res2))
		$tid = $rows[0];
	echo "<br>".$sql2."<br>".$tid."<br>";
		
	$rcnt=0;
	if($rev1 == "true")
		$rcnt++;
	if($rev2 == "true")
		$rcnt++;
	if($rev3 == "true")
		$rcnt++;
	$tid=$tid-$rcnt;
		
	$sql3="insert into transactiondetails(tranid,PNR,`Pax Name`,`Ticket Number`,`Travel Date`,`Return Date`,Sector,Basic,Admincharges,Tax,Amount,`Bkng Date`) values($tid,'$pnr','$pax','$tno',case when $tdlen > 2 then '".date("Y-m-d", strtotime($tdt1))."' else NULL end,case when $rdlen > 2 then '".date("Y-m-d", strtotime($rdt1))."' else NULL end,'$sec','$bc','$ac','$tax','$amt',case when $bdlen > 2 then '".date("Y-m-d", strtotime($bdt1))."' else NULL end);";
	$res3=mysql_query($sql3);
	
	if($nature=='1')		
		$sql4="update transactionmast set debitamt=$upddr where trnid=$tid";
	else if($nature=='15')
		$sql4="update transactionmast set creditamt=$updcr where trnid=$tid";
	$res4=mysql_query($sql4);	
	
	echo $sql3."<br>".$res3;
	echo $sql4."<br>".$res4;
?>